package services

import (
	"encoding/json"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/http"
)

type CallBackData struct {
	CallbackCommand string
	CallbackData    interface{}
}

type LivePushData struct {
	AnchorName string
	Title      string
	Thumb      string
}

func cbURL() string {
	return global.Config.GetString("callback.url")
}

func CallbackLivePush(livePushData *LivePushData) error {
	if !global.Config.GetBool("live_push.enable") {
		return nil
	}
	callBackData := CallBackData{
		CallbackCommand: "LivePushChannel",
		CallbackData:    livePushData,
	}
	bytes, err := json.Marshal(callBackData)
	if err != nil {
		global.Log.Error("livePush error: ", err)
		return err
	}
	_, err = http.HttpPost(cbURL(), string(bytes), 5000, 10000, "application/json")
	if err != nil {
		global.Log.Error("livePush error: ", err)
		return err
	}
	return nil
}
